﻿(function () {
    $(function () {

        var _$table = $('#tb');
        var _seatInfoService = abp.services.app.seatInfo;

        var _permissions = {
            create: abp.auth.hasPermission("Pages.Bom.SeatInfos.Create"),
            edit: abp.auth.hasPermission("Pages.Bom.SeatInfos.Edit"),
            'delete': abp.auth.hasPermission("Pages.Bom.SeatInfos.Delete")
        };


        var _createOrEditModal = new app.ModalManager({
            viewUrl: abp.appPath + 'SeatInfos/CreateOrEditSeatInfoModal',
            scriptUrl: abp.appPath + 'Views/SeatInfos/_CreateOrEditSeatInfoModal.js',
            modalClass: 'CreateOrEditSeatInfoModal'
        });
        $("input[name=PlanDate]").datepicker({
            autoclose: true,
            isRTL: false,
            format: "yyyy-mm-dd",
            pickerPosition: ("bottom-left"),
            //默认为E文按钮要中文，自己去找语言包
            todayBtn: true,
            todayHighlight: true,
            language: "zh-CN"
        });

    

        // #region CRUD按钮操作

    
    


        //导出为excel文档
        $('#btn-export').click(function () {
            layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
            _seatInfoService
                .getSeatInfoToExcel({})
                .done(function (result) {
                    layer.closeAll('loading');
                        app.downloadTempFile(result);
                    });
        });
        $("#btn-query").click(function () {
            $.ajax({
                type: "get",
                url: "/Reports_UPH/GetReports",
                data: {
                    date: document.getElementById("PlanDate").value,
                    lineID: document.getElementById("lineId").value,
                },
                dataType: 'JSON', //返回数据的格式
                contentType: 'application/json',
                success: function (data, status) {
                    var jsonobj = eval(data);
                    var a = [];
                    var b = [];
                    var c = [];
                    
                   
                    $('#line1').empty();
                    $('#line2').empty();
                    $('#line3').empty();
                    html = "<div class='text-center' style='border-bottom: 1px solid black;border-left: 1px solid black;  width: 10%'>区分</div>";
                    $("#line1").append(html);
                    html = " <div class='text-center' style='border-bottom: 1px solid black;border-left: 1px solid black;  width: 10%'>累计产量</div>";
                    $("#line2").append(html);
                    html = "  <div id='UPH_Time_7' class='text-center' style='border-bottom: 1px solid black;border-left: 1px solid black;  width: 10%'>UPH</div>";
                    $("#line3").append(html);
                    $.each(jsonobj, function (i, item) {
                        html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;  width: 10%'>" + item.time + "</div>";
                        $("#line1").append(html);
                        a.push(item.time);
                        html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px solid black;  width: 10%'>" + item.qty + "</div>";
                        $("#line2").append(html);
                        b.push(item.qty);
                        html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px solid black;  width: 10%'>" + item.UPH + "</div>";
                        $("#line3").append(html);
                        c.push(item.time);
                    });


                    var myChart3 = echarts.init(document.getElementById('chart3'));
                    option3 = {
                        title: {
                            text: 'db',
                            subtext: ''
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['15°', '25°']
                        },
                        toolbox: {
                            show: true,
                            feature: {
                                mark: { show: true },
                                dataView: { show: true, readOnly: false },
                                magicType: { show: true, type: ['bar', 'line'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        calculable: true,
                        grid: [
                        {
                            y2: '10'
                        }
                        ],
                        xAxis: [
                            {
                                type: 'category',
                                data: a
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: [
                            {
                                name: '15°',
                                type: 'line',
                                data: b,
                                markPoint: {
                                    data: [
                                    ]
                                }
                            },
                             {
                                 name: '25°',
                                 type: 'bar',
                                 data:b,
                                 markPoint: {
                                     data: [
                                     ]
                                 }
                             }
                        ]
                    };
                    myChart3.setOption(option3);
                    $("#maininput3").val(myChart3.getDataURL({
                        type: 'JPG',
                        pixelRatio: 5,
                        //backgroundColor: '#fff'
                    }));

                    var imgurl3 = myChart3.getDataURL({
                        type: 'JPG',
                        pixelRatio: 5,
                        //backgroundColor: '#fff'
                    });
                },
                error: function () {
                    abp.notify.error('Error');
                },
            });
        });

        //制作SeatInfo事件,用于请求变化后，刷新表格信息
        abp.event.on('app.createOrEditSeatInfoModalSaved', function () {
            _$table.bootstrapTable('refresh');
        });
        var oTable = new TableInit();
        oTable.Init();
        _$table.bootstrapTable('hideColumn', 'Id');

        //下拉框二级联动
        $("#cartypeId").change(function () {
            //获取工厂的ID
            var factoryID = $("#cartypeId").val();
            //获取车间
            var lst = $("#styleId");
            $.ajax({
                type: "get",
                url: "/Styles/GetAllStyleByCartypeId",
                data: { id: factoryID },
                dataType: 'JSON', //返回数据的格式
                contentType: 'application/json',
                success: function (data, status) {
                    if (status == "success") {
                        lst.empty();//清空下拉框
                        //lst.append("<option value=''> </option>");
                        $.each(data, function (i, item) {
                            lst.append("<option value='" + data[i].Value + "'>" + data[i].DisplayText + "</option>");

                        });

                        lst.selectpicker('refresh');
                        lst.selectpicker({
                            title: '请选择'
                        });
                    }
                },
                error: function () {
                    abp.notify.error('Error');
                },
            });
        });
    });
})();
